﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using coliseu.BussinessLayer;

namespace coliseu
{
    public partial class FrmCadApartamento : Form
    {
        private ApartamentoBL apBL;
        private apartamento ap;
        private BlocoBL bl = new BlocoBL();
          

        public FrmCadApartamento(ApartamentoBL apBL)
        {
            InitializeComponent();
            this.apBL = apBL;
            apartamentoBindingSource.AddNew();
        }


        public FrmCadApartamento(ApartamentoBL apBL, apartamento ap)
        {
            InitializeComponent();
            this.apBL = apBL;
            this.ap = ap;

            apartamentoBindingSource.DataSource = ap;            
        }

        private void FrmCadApartamento_Load(object sender, EventArgs e)
        {
            blocoBindingSource.DataSource = bl.selecionar();
            comboBox1.SelectedValue = ((apartamento)apartamentoBindingSource.Current).id_bloco;
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            ((apartamento)apartamentoBindingSource.Current).id_bloco = ((bloco)blocoBindingSource.Current).id_bloco;
            ((apartamento)apartamentoBindingSource.Current).situacao = comboBox2.Text;
            apartamentoBindingSource.EndEdit();

            if (ap == null)
                apBL.salvar((apartamento)apartamentoBindingSource.Current, "insert");
            else
                apBL.salvar((apartamento)apartamentoBindingSource.Current, "edit");

            MessageBox.Show("Salvo com sucesso", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information);
            Close();
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
